package com.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dao.AreaDao;
import com.enetiy.Area;
import com.enetiy.Areainfo;
import com.enetiy.Areatype;
import com.enetiy.Hotspot;

public class AreaDaoImpl extends HibernateDaoSupport implements AreaDao {
	public Area selectArea(int id) throws Exception {
		Area area = this.getHibernateTemplate().get(Area.class, id);
		return area;
	}
	public Area selectArea(String order)throws Exception{
		Query query = this.getSession().createQuery("from Area where area_order=?");
		query.setParameter(0, order);
		List<Area> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}
	
	
	@Override
	public List<Area> slelectList() throws Exception {
		List<Area> find = this.getHibernateTemplate().find("from Area");
		return find;
	}
	
	
	@Override
	public Hotspot selectHotspotOne(String hodpotName, Area area)
			throws Exception {
		Query query = this.getSession().createQuery("from Hotspot where hotspot_name=? and area_id=?");
		query.setParameter(0, hodpotName);
		query.setParameter(1, area.getId());
		List<Hotspot> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}
	
	@Override
	public Areainfo selsctAreainfo(int areaid, int areaiden)throws Exception {
		Query query = this.getSession().createQuery("from Areainfo where aeraid=? and iden=?");
		query.setParameter(0, areaid);
		query.setParameter(1, areaiden);
		List<Areainfo> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}
	
	
	@Override
	public Areatype selectAreatype(int iden) throws Exception {
		Query query = this.getSession().createQuery("from Areatype where iden=?");
		query.setParameter(0, iden);
		List<Areatype> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}
	@Override
	public Areatype selectAreatype(int iden, int bandwidth) throws Exception {
		Query query = this.getSession().createQuery("from Areatype where iden>? and banfwidth");
		query.setParameter(0, iden);
		query.setParameter(1,  bandwidth);
		List<Areatype> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}
	@Override
	public Areatype selectAreatypeid(int id) throws Exception {
		Areatype areatype = this.getHibernateTemplate().get(Areatype.class, id);
		return areatype;
	}
}
